﻿using System;
using Cubicle.Core.Config;
using Cubicle.Core.Interfaces;
using Cubicle.Core.Shared;

namespace Cubicle.Core.Processors
{

    public abstract class Processor : IProcessor
    {
        private ProcessorConfig _config;

        public ProcessorConfig Config
        {
            get { return _config; }
            set
            {
                // Check if there is a config field and set it
                _config = value;

                // Check if config is null
                if (value == null) return;

                // Set each of the parameters
                foreach (var p in value.Parameters)
                    this.SetField(p.Key, p.Get());
            }
        }

        public event EventHandler ProcessorEvent = delegate { };
        public virtual IProcessor Parent { get; set; }

        public void RaiseProcessorEvent(object sender, EventArgs e)
        {
            ProcessorEvent(sender, e);
        }
        
    }

    public abstract class Processor<T> : Processor, IProcessor<T>
    {

        public abstract T Process(T input);

    }
}